cmake_minimum_required(VERSION 3.5)

project(Forbidden_City VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find Qt libraries
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

# Include directories
include_directories(include)

# Project sources
set(PROJECT_SOURCES
    src/main.cpp
    src/mainwindow.cpp
    include/mainwindow.h
    src/mainwindow.ui  # Correct path to the UI file
)

# Conditional compilation based on Qt version
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(Forbidden_City
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
        resources/resources.qrc
        include/fileutils.h
        src/fileutils.cpp
        include/genetic_algorithm.h
        src/genetic_algorithm.cpp
        src/dijkstra.cpp
        include/dijkstra.h
        include/floyd_warshall.h
        src/floyd_warshall.cpp
        include/spfa.h
        src/spfa.cpp
        include/location_search.h
        src/location_search.cpp
        include/ant_colony_optimization.h
        src/ant_colony_optimization.cpp
        include/travellabel.h
        src/travellabel.cpp
        src/queue_network.cpp
        include/queue_network.h
        src/a_star.cpp
        include/a_star.h



    )
else()
    if(ANDROID)
        add_library(Forbidden_City SHARED
            ${PROJECT_SOURCES}
        )
    else()
        add_executable(Forbidden_City
            ${PROJECT_SOURCES}
        )
    endif()
endif()

# Link Qt Widgets library
target_link_libraries(Forbidden_City PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

# Set target properties for macOS and Windows
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.Forbidden_City)
endif()
set_target_properties(Forbidden_City PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

# Installation directories
include(GNUInstallDirs)
install(TARGETS Forbidden_City
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

# Finalize executable for Qt 6
if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(Forbidden_City)
endif()
